;!function(){
  var layer = layui.layer
  ,table = layui.table
  ,form = layui.form;
  
    form.render(); //更新全部
	form.render('select'); //刷新select选择框渲染
  
  table.render({
    elem: '#test'
    ,url:'/json/table1.json'
    ,height: 325 //容器高度
    ,toolbar: '#toolbarDemo'
    ,title: '订单数据表'
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
      ,{field:'username', title:'用户名', width:120, edit: 'text'}
      ,{field:'email', title:'邮箱', width:150, edit: 'text', templet: function(res){
        return '<em>'+ res.email +'</em>'
      }}
      ,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}
      ,{field:'city', title:'城市', width:100}
      ,{field:'sign', title:'签名'}
      ,{field:'experience', title:'积分', width:80, sort: true}
      ,{field:'ip', title:'IP', width:120}
      ,{field:'logins', title:'登入次数', width:100}
      ,{field:'joinTime', title:'加入时间', width:120}
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
    ]]
    ,page: false
  });
  
  //头工具栏事件
  table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'getCheckData':
        var data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      break;
      case 'getCheckLength':
        var data = checkStatus.data;
        layer.msg('选中了：'+ data.length + ' 个');
      break;
      case 'isAll':
        layer.msg(checkStatus.isAll ? '全选': '未全选');
      break;
    };
  });
  
  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //console.log(obj)
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        obj.del();
        layer.close(index);
      });
    } else if(obj.event === 'edit'){
      layer.prompt({
        formType: 2
        ,value: data.email
      }, function(value, index){
        obj.update({
          email: value
        });
        layer.close(index);
      });
    }
  });
  
  
  
  table.render({
    elem: '#gkbh'
    ,height: 312
    ,url:'/json/user1.json'
    ,page: true //开启分页
    ,cols: [[ //表头
      {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
      ,{field: 'username', title: '用户名', width:80}
      ,{field: 'sex', title: '性别', width:80, sort: true}
      ,{field: 'city', title: '城市', width:80} 
      ,{field: 'sign', title: '签名', width: 177}
      ,{field: 'experience', title: '积分', width: 80, sort: true}
      ,{field: 'score', title: '评分', width: 80, sort: true}
      ,{field: 'classify', title: '职业', width: 80}
      ,{field: 'wealth', title: '财富', width: 135, sort: true}
    ]]
  });
  
  
  //监听导航点击
//element.on('nav(demo)', function(elem){
//  //console.log(elem)
//  layer.msg(elem.text());
//});
//
  


  
    $('.sy_guke').on('click', function(){
    parent.layer.open({
	    type: 2,
	    title: '顾客验证',
	    maxmin: true,
	    moveOut: true,
	    area: ['680px', '500px'],
	    content: '/page/guke_yz.html'
	    ,zIndex: layer.zIndex //重点1
	  });
  });
  
$('.gk_bianhao').on('click', function(){
    parent.layer.open({
	    type: 2,
	    title: '顾客编号选择',
	    maxmin: true,
	    moveOut: true,
	    area: ['1000px', '800px'],
	    content: '/page/guke_bh.html'
	    ,zIndex: layer.zIndex //重点1
        ,success: function(layero){
          parent.layer.setTop(layero); //重点2
        }
	  });
});
  
  
  
  
  
}();